package com.example.codec;

import org.jboss.marshalling.*;

import java.io.IOException;

/**
 * <p>  </p>
 *
 * @author Chris
 * @since 2024/3/30 10:17
 */
public class MarshallingCodecFactory {

    /**
     * 创建 JBoss Marshaller
     *
     * @return JBoss Marshaller
     * @throws IOException from {@link MarshallerFactory#createMarshaller(MarshallingConfiguration)}
     */
    protected static Marshaller buildMarshalling() throws IOException {
        final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
        final MarshallingConfiguration configuration = new MarshallingConfiguration();
        configuration.setVersion(5);
        return marshallerFactory.createMarshaller(configuration);
    }

    /**
     * 创建 JBoss Unmarshaller
     *
     * @return JBoss Marshaller
     * @throws IOException from {@link MarshallerFactory#createMarshaller(MarshallingConfiguration)}
     */
    protected static Unmarshaller buildUnmarshalling() throws IOException {
        final MarshallerFactory marshallerFactory = Marshalling.getProvidedMarshallerFactory("serial");
        final MarshallingConfiguration configuration = new MarshallingConfiguration();
        configuration.setVersion(5);
        return marshallerFactory.createUnmarshaller(configuration);
    }

}